import { toJS } from 'mobx';
import { Button } from 'antd';
import { inject, observer } from 'mobx-react';
import { WeaTools, WeaProgress, WeaDialog } from 'ecCom';
import BaseList from '../BaseList';
import * as Rctt from '../../constants/BaseListConstant';
// import WeaWorkplan from 'weaWorkplan';
// const WorkPlanCreate = WeaWorkplan.com.WorkPlanCreate;
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

@inject('contactLogReportStore')
@observer
class Report extends BaseList {
  constructor(props) {
    super(props);
    window._contactLogTable = {
      reLoad: props.contactLogReportStore.reLoad,
    };
    if (window.weaWorkplan) {

    } else {
      // 异步加载别模块的静态资源
      eventRegister.loadModule('f_workplan', () => {
        // 加载成功
      }, () => {
        // 加载文件失败 的业务处理， 网络超时，没文件之类
        alert('加载日程模块失败，请联系系统管理员！');
      });
    }
  }

  getStore() {
    return this.props.contactLogReportStore;
  }

  getTabSearchTypes(store) {
    const arr = [];
    arr.push(Rctt.TAB_SEARCH_TYPE_BASE);
    arr.push(Rctt.TAB_SEARCH_TYPE_ADVANCED);
    return arr;
  }

    onOperatesClick = (record, index, operate, flag) => {
      const contactLogReportStore = this.props.contactLogReportStore;
      const _href = operate && operate.href ? operate.href : '';
      let fn = _href.replace('javascript:', '');
      fn = fn.substring(0, fn.indexOf('('));
      const that = this;
      if (fn != '') {
        if (fn == 'setContactStatus') {
          contactLogReportStore.setContactStatus(record.randomFieldId);
        }
      }
    }

    reRenderColumns = (columns) => {
      columns.forEach((c) => {
        if (c.dataIndex == 'name') {
          const store = this.getStore();
          c.render = function (text, record) {
            const valueSpan = record[`${c.dataIndex}span`] !== undefined ? record[`${c.dataIndex}span`] : record[c.dataIndex];
            if (record.namespan) {
              return <span onClick={() => { store.showWorkPlanDialog(true, record.randomFieldId); }} ><a>{record[c.dataIndex]}</a></span>;
            }
            return <span dangerouslySetInnerHTML={{ __html: valueSpan }} />;
          };
        }
      });
      return columns;
    }

    renderAppend(store) {
      const coms = [];
      let WorkPlanCreate = {};
      if (window.weaWorkplan) {
        WorkPlanCreate = weaWorkplan.com.WorkPlanCreate;
        const account = WeaTools.ls.getJSONObj('theme-account');
        const workplan =
            (<WorkPlanCreate
              ecId={`${this && this.props && this.props.ecId || ''}_WorkPlanCreate@qyoc4e`}
              type={'preview'}// 新建为'create',查看为'preview',编辑edit,共享share
              visible={store.workplanDialog.visible}// 显隐受控
              doClose={store.onlyClose}// 关闭回调
              onlyClose={store.onlyClose}// 关闭回调,只做关闭操作
              workPlanId={store.workplanDialog.workPlanId} // 日程id，查看日程时用到
              createConditionParams={[]}// 创建的默认值日期和时间,没有传[]
              activeKey={store.workplanDialog.activeKey} // 查看页面显示的面板1是基本信息，7是相关交流
              changeTab={store.changeTab}// 查看页面切换面板的回调
              selectUser={account ? account.userid : 1}// 新建日程的创建人id
              workPlanTypeOptions=""// 客户模块的新建日程，普通新建传'',客户新建传3
              crmIDs={''}// 通过客户模块新建日程，并自动带出相关客户,[{'id':'','name':''}]
              description=""// 客户模块需求，支持新建时传入的'基本信息-内容'
              previewCondition={{}}
            />);
        coms.push(workplan);
      }
      return coms;
    }
}

export default WeaTools.tryCatch(React, props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@8w6rk4`} msg={props.error ? props.error : getLabel(129417, '服务器运行出错，请联系系统管理员！')} />, { error: '' })(Report);
